<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		 <meta name="renderer" content="webkit">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>管理员列表</title>
	</head>
	<link rel="stylesheet" href="/Public/frame/layui/css/layui.css">
	<link rel="stylesheet" href="/Public/frame/static/css/style.css">
	<body>
		<button class="layui-btn" onclick="location.href='<?php echo U('add');?>'" style="margin-top: 10px;"><i class="layui-icon">&#xe654;</i>添加管理员</button>
        <button class="layui-btn" id="allot" style="margin-top: 10px;"><i class="layui-icon">&#xe654;</i>分配部门</button>
        <button class="layui-btn" id="allotrole" style="margin-top: 10px;"><i class="layui-icon">&#xe654;</i>分配角色</button>
        <button class="layui-btn" type="button" id="test3" style="margin-top: 10px;"><i class="layui-icon">&#xe67c;</i>用户导入</button>
        <a class="layui-btn btn-add btn-default" id="btn-refresh"style="margin-top: 10px;"><i class="layui-icon">&#x1002;</i></a>
        <form class="layui-form" id="search_form" action="/index.php/Hawk/Admin/lst" method="post">
            <div class="layui-form-item" style="margin-top:10px;">
                <div class="layui-inline">
                    <label class="layui-form-label">手机号：</label>
                    <div class="layui-input-inline">
                        <select name="username" lay-verify="" lay-search="">
                            <option value="">直接选择或搜索选择</option>
<?php foreach ($list as $k => $v): if($v['username']==$search['username']) $select = 'selected="selected"'; else $select = ''; ?>
                            <option <?php echo ($select); ?> value="<?php echo ($v['username']); ?>"><?php echo ($v['username']); ?></option>
<?php endforeach;?>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">姓名：</label>
                    <div class="layui-input-inline">
                        <select name="nickname" lay-verify="" lay-search="">
                            <option value="">直接选择或搜索选择</option>
<?php foreach ($list as $k => $v): if($v['nickname']==$search['nickname']) $select = 'selected="selected"'; else $select = ''; ?>
                            <option <?php echo ($select); ?> value="<?php echo ($v['nickname']); ?>"><?php echo ($v['nickname']); ?></option>
<?php endforeach;?>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">部门：</label>
                    <div class="layui-input-inline">
                        <select name="part_id" class="clean" lay-verify="" lay-search="">
                            <option value="">直接选择或搜索选择</option>
<?php foreach ($part as $k => $v): if($v['id']==$search['part_id']) $select = 'selected="selected"'; else $select = ''; ?>
                            <option <?php echo ($select); ?> value="<?php echo ($v['id']); ?>"><?php echo ($v['name']); ?></option>
<?php endforeach;?>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </form>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
            <legend>用户列表</legend>
        </fieldset>
    	<table class="layui-table" border="" cellspacing="" cellpadding="" width="100%">
    		<thead>
    			<tr>
                    <td width="5%"></td>
    				<td width="15%">用户名</td>
                    <td width="20%">昵称</td>
                    <td width="15%">部门</td>
                    <td width="15%">角色</td>
    				<td width="10%">是否在用</td>
    				<td width="20%">操作</td>
    			</tr>
    		</thead>
            <tbody>
<?php foreach ($data as $k => $v):?>
            	<tr class="allot">
                    <td width="5%"><input type="checkbox" name="id" value="<?php echo $v['id'];?>" /></td>
            		<td><?php echo $v['username']?></td>
                    <td><?php echo $v['nickname']?></td>
                    <td><?php echo $v['part_name']==''?'无':$v['part_name'];?></td>
                    <td><?php echo $v['role_name']==''?'无':$v['role_name'];?></td>
            		<td><?php echo $v['is_use']==1?'启用':'禁用';?></td>
            		<td>           		 
					  <a href="<?php echo U('edit',array('id'=>$v['id']))?>" class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
                      <a href="javascript:void(0);" class="layui-btn layui-btn-warm layui-btn-mini recycle" lay-event="recycle" uid="<?php echo $v['id'];?>" is_use="<?php echo $v['is_use'];?>" ><?php echo $v['is_use']==1?'禁用':'恢复';?></a>
					  <a href="<?php echo U('delete?id='.$v['id'].'&p='.I('get.p')); ?>" onclick="return confirm('确定要删除吗？');" class="layui-btn layui-btn-danger layui-btn-mini hahaha" lay-event="del" uid="<?php echo $v['id'];?>">删除</a>
            		</td>
                    
            	</tr>
<?php endforeach;?>  
<?php if(preg_match('/\d/', $page)): ?>  
        <tr><td align="right" nowrap="true" colspan="99" height="30" class="page"><?php echo $page; ?></td></tr> 
<?php endif; ?>          
            </tbody>
    	</table>				
	</body>
	<script type="text/javascript" src="/Public/hawk/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/Public/hawk/js/public.js"></script>
    <script type="text/javascript" src="/Public/frame/layui/layui.js"></script>
	<script>
	$(function(){
       
		$(document).on('click','.hahaha',function(){
			$(this).parents('tr').remove();
		});		
	});
    layui.use(['layer','upload','form'], function () {

        // 操作对象
        var layer       = layui.layer
            ,upload     = layui.upload
            ,form       = layui.form
            ,$          = layui.jquery;

        $(document).on('click','.recycle',function(){

            var uid = $(this).attr('uid');

            var is_use = $(this).attr('is_use');

            $.post("/index.php/Hawk/Admin/recycle",{'id':uid,'is_use':is_use},function(data){

                var obj = eval('(' + data + ')');

                layer.msg(obj['msg']);

                setTimeout('location.reload()',1000);
               
            });
            return false;
        });
        //分配部门
        $(document).on('click','#allot',function(){
            var data = $('.allot').find('input[name=id]:checked');
            var id='';
            data.each(function(){
                id+=','+$(this).val();
            });
            id = id.substring(1);
            if(id==''){
                layer.msg('请选择用户！');
                return false;
            }
            layer.open({
              type: 2,
              title:'部门信息',
              area: ['70%', '80%'],
                  fixed: false, //不固定
                  maxmin: true,
                  content: '/index.php/Hawk/Admin/allot/id/'+id
            });
        });
        //分配角色
        $(document).on('click','#allotrole',function(){
            var data = $('.allot').find('input[name=id]:checked');
            var id='';
            data.each(function(){
                id+=','+$(this).val();
            });
            id = id.substring(1);
            if(id==''){
                layer.msg('请选择用户！');
                return false;
            }
            layer.open({
              type: 2,
              title:'角色信息',
              area: ['70%', '80%'],
                  fixed: false, //不固定
                  maxmin: true,
                  content: '/index.php/Hawk/Admin/allotrole/id/'+id
            });
        });
        //导入用户
        upload.render({
            elem: '#test3'
            ,url: '/index.php/Hawk/Admin/upload'
            ,accept: 'file'
            ,before:function(obj){
                layer.load(); //上传loading
            }
            ,done: function(res){
                layer.closeAll('loading');//导入完毕清除loading
                layer.msg(res.msg);
            }
            ,error: function(){
                layer.msg('模块失效，请联系技术部！');
            }
        });
    });	
</script>
</html>